/*

制作转发微博的图片的思路,首先使用collectionview布局控件,然后就是对空间里面不同的数量进行不同的布局,每一个collectionViewCell里面是一个imageView,为了显示其里面cell的数量,我们使用一个
label来标识对应的数量





*/

import UIKit

import SnapKit

//为什么在cell中设置字体呢

//设置头像大小
let CZHomeCellHeadImageWH: CGFloat = 35

//设置名字的字体大小
let CZHomeCellNameFontSize: CGFloat = 14


//时间与来源的字体大小
let CZHomeCellTimeFontSize: CGFloat = 10

//设置cell里面的公共间距
//10
let CZHomeCellMargin: CGFloat = 10
//设置内容的字体大小
let CZHomeCellContentFontSize: CGFloat = 14

let CZHomeCellBottomViewH: CGFloat = 35


class CZHomeCell: UITableViewCell {
    
    
    //设置约束,获取toolBar的顶部的约束
    
    var toolBarCons: Constraint?
    
    //数据源
    var statusViewModel: CZStatusViewModel? {
        didSet{
            
            originalView.statusViewModel = statusViewModel
            
            //要让topbar的约束失效
            toolBarCons?.uninstall()
            
            if statusViewModel?.status?.retweeted_status != nil {
               
                //设置数据
                
                retweetView.statusViewModel = statusViewModel
                //显示转发微博视图
                retweetView.hidden = false
                //更改约束,是一retweetview来进行设置
                toolBar.snp_updateConstraints(closure: { (make) -> Void in
                    
                    toolBarCons = make.top.equalTo(retweetView.snp_bottom).constraint
                    
                })
                
                
                
                
                
            }else{
                //没有转发微博,将转发设置为隐藏
                
                retweetView.hidden = true
                //更新toolbar的约束
                toolBar.snp_updateConstraints(closure: { (make) -> Void in
                    
                    toolBarCons = make.top.equalTo(originalView.snp_bottom).constraint
                })
                
                
                
            }
            
            
            
            
        }
        
        
    }
    
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
         setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI(){
        
        //设置contentView的背景颜色
        
        contentView.backgroundColor = UIColor(white: 180/255, alpha: 1)
        
        //设置选中的样式
        selectionStyle = .None
        
        //添加控件
        
        contentView.addSubview(originalView)
        
        contentView.addSubview(toolBar)
        
        contentView.addSubview(retweetView)
        
        //设置约束
        
        originalView.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(contentView).offset(CZHomeCellMargin)
           make.leading.trailing.equalTo(contentView)
        
            //为了测试高度
//            make.height.equalTo(80)
            
        }
        
        //toolbar 设置约束
        
        toolBar.snp_makeConstraints { (make) -> Void in
            
            make.leading.trailing.equalTo(originalView)
       toolBarCons = make.top.equalTo(retweetView.snp_bottom).constraint
            make.height.equalTo(CZHomeCellHeadImageWH)
            
        }
        //设置约束,转发微博的约束
        retweetView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(originalView.snp_bottom)
            make.leading.trailing.equalTo(originalView)
            
        }
        
        
        
        contentView.snp_makeConstraints { (make) -> Void in
            
            make.bottom.equalTo(toolBar.snp_bottom)
            
            make.top.leading.trailing.equalTo(self)
        }
////
        
        
      
    }
    
    
    //懒加载空间
    
    private lazy var originalView: CZStatusView = CZStatusView()
    
    //懒加载bar
    
    private lazy var toolBar: CZStatusToolBar = CZStatusToolBar()
  //懒加载转发微博的label
    private lazy var retweetView: CZRetweetStatusView = CZRetweetStatusView()
    
    
    
    
    
    
    
    
    

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
